package pms.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import pms.dao.PersonDeleteException;


/**
 * <p>
 * Controller to generate the Home Page basics to be rendered by a view. 
 * It extends the convenience class AbstractController that encapsulates most 
 * of the drudgery involved in handling HTTP requests. 
 * </p>
 * 
 * <p>
 * ModelAndView contains
 * <ul>
 * <li>title: Will be used as a headline in the resulting view</li>
 * <li>message: Some hints for the user</li>
 * </ul>
 * @author KRS DEV Team (krsdevteam@PMSWIbb2011SS.de)
 */
public class LoescheRes extends AlleBuchungen {
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest httpServletRequest,
			HttpServletResponse httpServletResponse) throws Exception {
		int id = Integer.parseInt(httpServletRequest.getParameter("id"));
		try {
			getReservierungDao().deleteById(id);
			return super.handleRequestInternal(httpServletRequest, httpServletResponse);
		} catch (PersonDeleteException e) {
			ModelAndView mv = new ModelAndView();
			mv.addObject("title", "Ein Fehler ist aufgetreten");
			mv.addObject("message", e.getMessage());
			mv.setViewName("home");
			return mv;
		}
	}
}
